#ifndef NETCHECKMANAGER_H
#define NETCHECKMANAGER_H

#include "abstractchecker.h"

#include <map>
#include <vector>
#include <memory>
#include <atomic>
#include <thread>
#include <mutex>
#include <condition_variable>

class NetCheckManager
{
public:
    NetCheckManager();
    ~NetCheckManager();

    /**
     * @brief addChecker 添加一个检测者
     * @param checker
     * @param priority 优先级别，越小级别越高
     */
    void addChecker(std::shared_ptr<AbstractChecker> checker, int priority = 0);

    void startCheck();

    bool netConnected() { return m_netConnect.load(); }

private:
    void checkNetState();

private:
    std::map<int, std::vector<std::shared_ptr<AbstractChecker>>> m_checkers;
    std::atomic_bool m_netConnect;
    std::mutex m_mtx;
    std::condition_variable m_cv;
    std::thread *m_thread;
    bool m_threadRunning;
};

#endif // NETCHECKMANAGER_H
